<?php

namespace App\Http\Controllers;

use Illuminate\Support\Facades\DB;

class DataController extends Controller
{

    public function index(){
    	//查询
    	$data['select1'] = DB::select('select * from actor where last_name = ?', ['PECK']);//运行 Select 查询
    	$data['select2'] = DB::select('select * from actor where last_name = :last_name', ['last_name' => 'PECK']);//使用命名绑定
    	$data['select3'] = DB::table('actor')->get();//从一张表中取出所有行
    	$data['select4'] = DB::table('actor')->where('last_name','CHASE')->first();//从一张表中获取一行
    	$data['select5'] = DB::table('actor')->where('last_name','CHASE')->value('first_name');
    	$data['select6'] = DB::table('actor')->pluck('first_name');//获取数据列值列表
    	$data['select7'] = DB::table('actor')->pluck('first_name','actor_id');//为列值指定自定义键
    	DB::table('actor')->orderBy('actor_id')->chunk(100, function($actor) {
		    foreach ($actor as $val) {}
		});//组块结果集
    	$data['select8'] = DB::table('actor')->count();
    	$data['select9'] = DB::table('actor')->max('actor_id');

    	//插入
    	//DB::insert('insert into actor (first_name,last_name,last_update) value (?,?,?)',['Bob','Tom',date('Y-m-d h:i:s',time())]);//运行插入语句

    	//更新
    	$data['update1'] = DB::update('update actor set last_name = ? where first_name = ?',['jon','Bob']);//运行更新语句

    	//删除
    	$data['delete1'] = DB::delete('delete from actor where actor_id = ?',[201]);
    	dd($data);
    }

}

